package com.offcn;

import java.io.*;
import java.util.*;
import com.offcn.pojo.Student;

public class demo02 {
    public static void main(String[] args) {
        File file = new File("E:\\sanqing\\student.csv");
        try {
            BufferedReader br = new BufferedReader(new FileReader(file));
            Map<String,ArrayList> map = new LinkedHashMap<String, ArrayList>();
            ArrayList<Student> list = new ArrayList<Student>();
            String line = "";
            br.readLine();
            while ((line = br.readLine())!=null){
                //把一行数据分割成多个字段
                Student student = new Student();
                String[] split = line.split(",");
                student.setId(Integer.parseInt(split[0]));
                student.setName(split[1]);
                student.setYuwen(Integer.parseInt(split[2]));
                student.setShuxue(Integer.parseInt(split[3]));
                student.setYunyu(Integer.parseInt(split[4]));
                student.setWuli(Integer.parseInt(split[5]));
                student.setHuaxue(Integer.parseInt(split[6]));
                student.setShengwu(Integer.parseInt(split[7]));
                //循环从2开始，因为这里开始是成绩
                //设置一个变量
                int number = 0;
                for (int i = 2; i <= split.length-1; i++) {
                    int i1 = Integer.parseInt(split[i]);
                    number += i1;
                }
                student.setZong(number);
                list.add(student);
                map.put(split[0],list);
            }
            for (int i = 0; i < list.size()-1; i++) {
                for (int j = 1 + i; j < list.size(); j++) {
                    Student temp;
                    if (list.get(i).getZong() < list.get(j).getZong()) {
                        temp = list.get(i);
                        list.set(i,list.get(j));
                        list.set(j,temp);
                    }
                }
            }
            for(int i = 0; i < list.size()-1; i++) {
                for (int j = 1 + i; j < list.size(); j++) {
                    Student temp;
                    if (list.get(i).getZong() == list.get(j).getZong()) {
                        if (list.get(i).getId() > list.get(j).getId()) {
                            temp = list.get(i);
                            list.set(i, list.get(j));
                            list.set(j, temp);
                        }
                    }
                }
            }
            for (Student s:list
            ) {
                System.out.println(s);
            }
            br.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
